// 引入mockjs
import Mock from "mockjs";

// 获取 mock.Random 对象
const Random = Mock.Random;

// 使用mockjs模拟数据
let tableList = [
  {
    id: "5ffa80aD-9CF4-0C77-eBFC-f6612BfAcF4F",
    account: "admin",
    password: "123456",
    address: "36918166@qq.com",
  },
  {
    id: "4FcC922C-C72c-95c3-Ef92-FbFAc24cc831",
    account: "ebHoL6",
    password: "i320Hu74fbn2Gi",
    address: "48165263@qq.com",
  },
];

let treeData = [
  {
    id: 1,
    name: "一级 1",
    children: [
      {
        id: 4,
        name: "二级 1-1",
        children: [
          {
            id: 9,
            name: "三级 1-1-1",
          },
          {
            id: 10,
            name: "三级 1-1-2",
          },
        ],
      },
    ],
  },
  {
    id: 2,
    name: "一级 2",
    children: [
      {
        id: 5,
        name: "二级 2-1",
      },
      {
        id: 6,
        name: "二级 2-2",
      },
    ],
  },
  {
    id: 3,
    name: "一级 3",
    children: [
      {
        id: 7,
        name: "二级 3-1",
      },
      {
        id: 8,
        name: "二级 3-2",
      },
    ],
  },
];

let userList = [
  { id: 1, name: "健", personStatus: "0" },
  { id: 2, name: "蕾", personStatus: "0" },
  //   { id: 3, name: "丽", personStatus: "0" },
  //   { id: 4, name: "洁", personStatus: "0" },
  //   { id: 5, name: "颖", personStatus: "0" },
  //   { id: 6, name: "佳", personStatus: "0" },
  //   { id: 7, name: "珍", personStatus: "0" },
];


let flowTemplateList = {"node":{"id":"node_555399833640","name":"发起人","type":0,"status":-1,"childNode":{"id":"node_572298757660","name":"审批人","type":1,"status":-1,"config":{"assignedType":"ASSIGN_USER","approvalMode":"NEXT","sameMode":"AUTO","nobody":{"handler":"AUTO","assignedUser":[]},"reject":{"type":"TO_END","target":""},"leader":{"level":1},"role":[],"selfSelect":{"multiple":true},"levelMode":1,"approverIds":[],"approverNames":[],"formPerms":[],"configure":{},"assignedUser":[{"id":2,"name":"蕾","personStatus":"0"},{"id":1,"name":"健","personStatus":"0"}],"addable":true,"deletable":false,"error":false,"content":"蕾,健"},"childNode":{"id":"node_572468502928","name":"抄送人","type":2,"status":-1,"childNode":null,"config":{"approverGroups":[{"id":"node_572468502157","approverType":1,"levelMode":1,"approverIds":[],"approverNames":[]}],"formPerms":[],"configure":{},"assignedUser":[{"id":1,"name":"健","personStatus":"0"},{"id":2,"name":"蕾","personStatus":"0"}],"addable":true,"deletable":false,"error":false,"content":"健,蕾"},"pid":"node_572298757660"},"pid":"node_555399833640"},"config":{"formPerms":[{"id":"node_572255567215","name":"姓名","writable":true,"readable":false,"displayable":false,"required":true},{"id":"node_572255567298","name":"年龄","writable":true,"readable":false,"displayable":false,"required":true}],"configure":{},"content":"已设置","addable":true,"error":false}},"baseSetting":{"flowName":"测试流程表单","imageUrl":"http://img.jiansys.work/0479h20ZKe.png","flowGroup":"2","bindForm":"请假表单","description":"测试流程表单"},"formData":{"config":{"version":"0.5","formRef":"elForm","formModel":"form","rules":"rules","size":"default","labelPosition":"right","labelWidth":80,"formRules":"rules","gutter":15,"disabled":false,"dynamicTableAllowed":true},"list":[{"id":"fd_1694187763213","key":"fd_1694187763213","type":"input","name":"单行文本","icon":"input","viewType":"text","options":{"config":true,"showLabel":true,"placeholder":"请输入文本","required":false,"span":24,"width":"100%","clearable":true,"disabled":false,"readonly":false,"status":"normal","prefix-icon":"","suffix-icon":"","value":"","rulesType":"default","prepend":"","append":"","layout":"colItem"},"rules":[]},{"id":"fd_1694339881185","key":"fd_1694339881185","type":"input","name":"单行文本","icon":"input","viewType":"text","options":{"config":true,"showLabel":true,"label":"单行文本","placeholder":"请输入文本","required":false,"span":24,"width":"100%","clearable":true,"disabled":false,"readonly":false,"status":"normal","prefix-icon":"","suffix-icon":"","value":"","rulesType":"default","prepend":"","append":"","layout":"colItem"},"rules":[]},{"id":"fd_1694339882990","key":"fd_1694339882990","type":"select","name":"下拉框","icon":"select","viewType":"component","options":{"config":true,"label":"下拉框","placeholder":"请选择","span":24,"gutter":15,"labelWidth":80,"showLabel":true,"required":false,"multiple":false,"collapse-tags":false,"disabled":false,"filterable":false,"options":[{"label":"选项一","value":"1"},{"label":"选项二","value":"2"}],"dataType":"static","action":"https://www.fastmock.site/mock/51715c0157535b99010bde55f2df33c8/formDesigner/api/options","clearable":false,"modelValue":"","ruleError":"该字段不能为空","layout":"colItem"},"rules":[]}]}};

// for (let i = 0; i < 20; i++) {
//   let newObject = {
//     id: Random.guid(), // 获取全局唯一标识符
//     account: /^[a-zA-Z0-9]{4,6}$/,
//     password: /^[a-zA-Z]\w{5,17}$/,
//     address: /[1-9]\d{7,10}@qq\.com/,
//   };
//   tableList.push(newObject);
// }

Mock.mock("/api/mockTreeList", "get", () => {
  return {
    code: "0",
    data: treeData,
  };
});

Mock.mock("/api/mockOrgUserList", "get", () => {
  return {
    code: "0",
    data: userList,
  };
});

/** get请求
 * 获取用户列表
 */
Mock.mock("/api/mockGetList", "get", () => {
  return {
    code: "0",
    data: tableList,
  };
});

/** post请求添加表格数据 */
Mock.mock("/api/add", "post", (params) => {
  let newData = JSON.parse(params.body);
  newData.id = Random.guid();
  tableList.push(newData);
  return {
    code: "0",
    message: "success",
    data: tableList,
  };
});

Mock.mock("/api/getFlowTemplate", "get", () => {
  return {
    code: "0",
    data: flowTemplateList,
  };
});
